package com.bite.friend.controller.question;

import com.bite.common.core.controller.BaseController;
import com.bite.common.core.domain.R;
import com.bite.common.core.domain.TableDataInfo;
import com.bite.friend.domain.question.Question;
import com.bite.friend.domain.question.QuestionDetailVO;
import com.bite.friend.domain.question.QuestionQueryDTO;
import com.bite.friend.service.question.IQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/question")
public class QuestionController extends BaseController {
    @Autowired
    private IQuestionService questionService;


    @GetMapping("/semiLogin/list")
    public TableDataInfo list(QuestionQueryDTO questionQueryDTO){
    return questionService.list(questionQueryDTO);
    }
    //es速度略胜于mysql
    @GetMapping("/detail")
    public R<QuestionDetailVO> detail(Long questionId){
        //大体逻辑
        return R.ok(questionService.detail(questionId));
    }
    //题目的顺序列表,不然你不知道上一个下一个，你光有id,我们的id是随机的那个雪花,默认根据时间排序的，所以，我们只用id就行
    @GetMapping("/preQuestion")
    //返回下一道题的questionId,Long会被截断，所以使用String
    public R<String>  preQuestion(Long questionId){
        //我们需要找顺序，然后才能找上一个或者下一个，redis里面的list是保持插入的顺序的，所以我们只要在redis插入顺序正常的id就好啦。
        //list 数据类型 key：q:l value: questionId
       return  R.ok(questionService.preQuestion(questionId));
    }
    @GetMapping("/nextQuestion")
    public R<String>  nextQuestion(Long questionId){
    return R.ok(questionService.nextQuestion(questionId));
    }


}
